import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class main {

    public static void main(String[] args) {
        try {

            FileChannel fc = new RandomAccessFile(
                "/Users/mike/workspace/git/knowledge/系统学习/IO系统学习/NIO/Channel与Buffer/channelandbuffer/src/main/resources/test.txt",
                "rw").getChannel();
            ByteBuffer bf = ByteBuffer.allocate(1024);
            fc.read(bf);
            fc.read(bf);
            bf.flip();
            while (bf.hasRemaining()) {
                System.out.println(bf.get());
            }
            ByteBuffer bf2 = ByteBuffer.allocate(5);
            bf2.put("ddddd".getBytes());
            bf2.flip();
            fc.write(bf2);
            fc.close();
        } catch (Exception e) {

        }
    }
}
